package main

import "fmt"

func isValid(s string) bool {
	n := len(s)
	if n%2 == 1 {
		return false
	}
	stack := []byte{}
	mapS := make(map[byte]byte)
	mapS[')'] = '('
	mapS['}'] = '{'
	mapS[']'] = '['
	for i := 0; i < n; i++ {
		fmt.Println(stack)
		if mapS[s[i]] > 0 {
			if len(stack) == 0 || stack[len(stack)-1] != mapS[s[i]] {
				return false
			}
			stack = stack[:len(stack)-1]

		} else {
			stack = append(stack, s[i])
		}
	}
	return len(stack) == 0
}
func main() {
	s := "()[]{}"
	b := isValid(s)
	fmt.Println(b)
}
